Imports IICModel.BusObjects.Mappers
Imports IICModel.ConversionObjects.Mappers
Imports IICModel.BusObjects
Imports IICModel.ConversionObjects


Namespace DataConbversionLogic
    Public Class SubjectConverter
        Inherits BaseDataConverter

        Protected Overrides Sub mapData(ByVal source As org.model.lib.Model.IModelObject, _
                                        ByRef destination As org.model.lib.Model.IModelObject)

            Dim s As SUBJECTS = CType(source, SUBJECTS)
            Dim d As Lesson = CType(destination, Lesson)

            d.LessonCode = Trim(s.CODE)
            d.LessonName = Trim(s.DescVal)
            d.DataConversionSourceTable = getTableName()

            'these are PAS subjects so we hard code
            d.DefaultMaxGrade = 200
            d.DefaultPassGrade = INT_PAS_PASSING_GRADE

        End Sub

        Protected Overrides Sub instantiateMappers()

            Me.dataConvMapper = New SUBJECTSDBMapper()
            Me.newdbMapper = New LessonDBMapper

        End Sub

        Protected Overrides Function checkData(ByVal source As IModelObject, _
                                  ByVal destination As IModelObject) As Boolean

            If Me.newdbMapper.findWhere("LessonCode={0}", CType(source, SUBJECTS).CODE) Is Nothing Then
                Return True
            Else
                Me.logMsgFormat("LessonCode={0} Already exists.", CType(source, SUBJECTS).CODE)
                Return False
            End If

        End Function


        Protected Overrides Function getTableName() As String
            Return "SUBJECT"
        End Function

    End Class
End Namespace